import 'package:flutter/material.dart';
import 'package:qgchat/common/action/filter/index.dart';
import 'package:qgchat/common/class/date/index.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/apis/api.dart';
import 'package:qgchat/http/models/rechargeRecordModel.dart';
import 'package:qgchat/widgets/appbarCustom.dart';
import 'package:qgchat/widgets/noData.dart';

/**
 * 充值记录页面
 * page充值记录
 */

class RechargeRecord extends StatefulWidget {
  RechargeRecord(this.id, {Key key}) : super(key:key);

  final String id;

  @override
  _RechargeRecordState createState() => _RechargeRecordState();
}

class _RechargeRecordState extends State<RechargeRecord> {



// hook-------------------------------------------------------------------------

  @override
  void initState() {
  }

  bool isHasData = true;
  @override
  void reassemble() {
    isHasData = true;
    super.reassemble();
  }

// methods----------------------------------------------------------------------



// widget-----------------------------------------------------------------------


  /// appbar
  Widget appbar() {
    return AppbarCustom('充值记录');
  }

  /// 记录页面
  Widget getRecordPage() {
    if (!isHasData) {
      return NoData('aaa');
    } else {
      return Container(
        child: Column(
          children: <Widget>[
            /// 头
            Container(
              height: px(70),
              color: col('f5f7fa'),
              padding: EdgeInsets.symmetric(horizontal: px(30)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    '充值状态',
                    style: TextStyle(
                      fontSize: px(26),
                      color: col('909399'),
                    ),
                  ),
                  Text(
                    '充值金额',
                    style: TextStyle(
                      fontSize: px(26),
                      color: col('909399'),
                    ),
                  )
                ],
              ),
            ),
            /// 记录
            Container(
              child: Expanded(
                child: SafeArea(
                  top: false,
                  child: FutureBuilder(
                    future: UserApis.getRechargeRecord(widget.id),
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.done) {
                        List<RechargeRecordModel> list = snapshot.data;
                        return ListView.builder(
                          itemCount: snapshot.data.length,
                          physics: BouncingScrollPhysics(),
                          itemBuilder: (BuildContext context, int index) {
                            return rechargeRecordItemBuilder(
                              list[index].createTime,
                              list[index].good,
                            );
                          },
                        );
                      } else {
                        return Center(
                          child: CircularProgressIndicator(),
                        );
                      }
                    },
                  )
                )
              )
            )
          ],
        ),
      );
    }
  }

  /// 充值记录单项构造器
  Widget rechargeRecordItemBuilder(String createTime, String good) {
    return Container(
      height: px(120),
      margin: EdgeInsets.symmetric(horizontal: px(30)),
      decoration: BoxDecoration(
        border: Border(bottom: BorderSide(color: col('edeff2'), width: px(1)))
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          /// left
          Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                '充值成功',
                style: TextStyle(
                  fontSize: px(32),
                  color: col('303133'),
                ),
              ),
              Text(
                Date.simple(int.parse(createTime), format: 'y/m/d h:i'),
                style: TextStyle(
                  fontSize: px(28),
                  color: col('909399'),
                  height: 2,
                ),
              )
            ],
          ),
          /// right
          Text(
            '+'+good,
            style: TextStyle(
              fontSize: px(34),
              color: col('303133'),
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: appbar(),
      body: Container(
        child: getRecordPage(),
      ),
    );
  }
}
